package com.yin.webflux;

import com.yin.webflux.entity.User;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

/**
 * Client
 *
 * @author Yin Guiqing
 */
public class Client {
    public static void main(String[] args) {
        WebClient webClient = WebClient.create("http://localhost:8235");

        User user = webClient.get().uri("/user/{id}", 1)
                .accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(User.class)
                .block();
        System.out.println(user);

        Flux<User> users = webClient.get().uri("/users")
                .accept(MediaType.APPLICATION_JSON).retrieve().bodyToFlux(User.class);
        users.map(User::toString).buffer().doOnNext(System.out::println).blockFirst();
    }
}
